﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business.Classes;
using DAL;
using System.Collections.Generic;

namespace UI
{
    public partial class buscarPostNew : System.Web.UI.Page
    {
        TagBusiness tagBusiness = new TagBusiness();
        PostNewBusiness postNewBusiness = new PostNewBusiness();
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btPesquisa_Click(object sender, EventArgs e)
        {
            List<Tag> listTag = new List<Tag>();
            for (int i = 0; i < cblTags.Items.Count; i++)
            {
                if (cblTags.Items[i].Selected)
                    listTag.Add(tagBusiness.getTagByID(Convert.ToInt32(cblTags.Items[i].Value)));
            }

            DateTime datePesquisa = (!string.IsNullOrEmpty(txtData.Text) ? Convert.ToDateTime(txtData.Text) : DateTime.Now);
            gvPostNew.DataSource = postNewBusiness.getPostNewByParameters(txtConteudo.Text, txtUsuario.Text,
                datePesquisa, listTag);
            gvPostNew.DataBind();
        }


        protected void cblTags_Init(object sender, EventArgs e)
        {
            cblTags.DataSource = tagBusiness.getAllTags();
            cblTags.DataBind();
        }
    }
}
